

class Role:
    def __init__(self,name,sex,attack,defence,hp=100,armor=None):
        self.name = name
        self.sex = sex
        self.hp=hp
        self.attack = attack
        self.defence = defence
        self.armor = armor
        self.room = None


    def battle(self,target):
        if self.room == target.room:#房间一致
            if self != target: #不能打自己
                if self.hp > 0 and target.hp >0:
                    damage = (self.attack - target.defence)*0.5 if target.armor else (self.attack - target.defence)
                    target.hp -= damage
                    print(f"{self.name}对{target.name}造成了{damage}点伤害\t{self.name}当前血量：{self.hp}\t{target.name}当前血量：{target.hp}")
                else:
                    print("有选手倒下，游戏结束")
                    exit()
            else:
                print("不可以攻击自己")
        else:
            print("对方不在当前房间")



class Room:
    def __init__(self,name):
        self.member_lst=[]
        self.name = name

    def join(self,target):
        if target.room == None:
            if len(self.member_lst) < 2:
                self.member_lst.append(target)
                target.room = self.name
            else:
                print(f"{self.name}房间已满")
        else:
            print("已加入该房间")


role = {}
room_dict ={}



while 1:
    print("1.创建角色\n2.创建房间\n3.加入房间\n4.开始战斗\n5.退出")
    op = input("请输入选择：")
    if op == "1":
        name,sex,attack,defence = input("输入角色的名字、性别、攻击力和防御力\n").split()
        role[name] = Role(name,sex,int(attack),int(defence))
        weared = input("按e穿上防具")
        if weared == "e":
            role[name].armor = 1
    elif op == "2":
        name = input("请输入要创建的房间名字:")
        room_dict[name] = Room(name)
    elif op == "3":
        print(f"角色列表{role.keys()},房间列表{room_dict.keys()}")
        role_name, room_name = input("请输入要加入的角色和房间名\n").split()
        # 注：这里可以做1个判断 (考虑到各种情况),角色要一个一个进房间
        room_dict[room_name].join(role[role_name])
        continue
    elif op == "4":
        print(f"房间列表{room_dict.keys()}")
        room_name = input("选择房间")
        if len(room_dict[room_name].member_lst) == 2:
            round_count = 1
            while 1:
                print(f"第{round_count}回合")
                round_count += 1
                room_dict[room_name].member_lst[0].battle(room_dict[room_name].member_lst[1])
                room_dict[room_name].member_lst[1].battle(room_dict[room_name].member_lst[0])
        else:
            print(f"房间{room_name}人数不足2人")
            continue
    elif op == "5":
        print("退出对战")
        break



# 皮卡丘 雄 20 10 e 先手
# 喷火龙 雄 20 10 不装备





